<template>
  <view>
    <form>

      <xmInfo
      :projectno="dataInfo.projInfo.projectno"
      :projectname="dataInfo.projInfo.projectname"
    ></xmInfo>
      <view class="cu-form-group">
        <view class="title"><text class="cuIcon-kb text-xs text-red"></text>分单原因类型</view>
        <js-select disabled v-model="dataInfo.reasonid" dict-type="zf_fd_reason"
          style="text-align: right;"></js-select>
        
      </view>

      <view class="cu-form-group" style="min-height: 0"></view>
      <view class="cu-bar bg-white">
        <view class="action"><text class="cuIcon-kb text-xs text-red"></text>分单原因</view>
      </view>
      <view class="cu-form-group">
        <textarea
          maxlength="-1"
          :disabled="true"
          :value="dataInfo.remarks"
          placeholder="remarks"
        ></textarea>
      </view>

      <view class="cu-form-group" style="min-height: 0"></view>
      <view class="cu-bar bg-white">
        <view class="action"><text class="cuIcon-kb text-xs text-red"></text>分单附件</view>
      </view>
      <js-uploadfile
          v-model="dataInfo.dataMap"
          :biz-key="dataInfo.id"
          biz-type="ProjectSegmentation_image"
          :deletable="false"
          customBtn="false"
      ></js-uploadfile>
      <view class="cu-card"  v-if="dataInfo.pmProjectSplitNatureList && dataInfo.pmProjectSplitNatureList.length">
        <view
          class="cu-item shadow"
          v-for="(item, index) in dataInfo.pmProjectSplitNatureList"
          :key="index"
          v-if="item && item.status != 1"
        >
          <view class="cu-form-group">
            <view class="text-xl text-bold">
              <view
                  style="
                    display: inline-block;
                    padding: 5px;
                    background: #3e97b0;
                    color: #fff;
                    width: 40px;
                    text-align: center;
                    font-style: italic;
                    font-weight: bold;
                  "
                  class="margin-right-sm"
                >
                  {{ index + 1 }}
                </view>
                {{ item.metercode ? item.metercode : item.metercode }}</view>
            <view class="text-xl text-bold"></view>
          </view>
          <view class="cu-form-group padding">
            <view class="title">水表名称</view>
            <view>{{ item.metername  ? item.metername : '' }}</view>
          </view>
          <view class="cu-form-group">
            <view class="title">性质</view>
            <view>{{ item.naturecode }}{{ item.naturename ? "(" + item.naturename + ")" : '' }}</view>
          </view>
          <view class="cu-form-group">
            <view class="title">水表总数</view>
            <view>{{ item.metercount }}</view>
          </view>
          <view class="cu-form-group">
            <view class="title">剩余数量</view>
            <view>{{ item.nature.remaining }}</view>
          </view>
          <view class="cu-form-group">
            <view class="title text-red">本次安装数</view>
            <view>
              {{ item.splitedcount }}
              <!-- <input placeholder="请输入本次拆分数" name="input" v-model="item.splitedcount" class="input-align"/> -->
            </view>
          </view>
        </view>
      </view>
      <view style="height: 180rpx"></view>
      <view class="btn-group cu-bar foot cu-bar1">
        
        <view class="flex">
            <js-bpm-button
          v-model="dataInfo.bpm"
          :biz-key="dataInfo.id"
          form-key="Flow_PmProjectSegmentation"
          @complete="submit"
        ></js-bpm-button>
        </view>
      </view>
    </form>
  </view>
</template>
<script>

import xmInfo from "@/pages/zfgs/index/componetns/xmInfo.vue";
import {hasPermission} from '@/common/fire.js'
export default {
  components: {
    xmInfo
  },
  data() {
    return {
      uploadOptions: {},
      switchA: false,
      date: new Date().toISOString().substring(0, 10),
      modalName: null,
      modalNameDetail: null,
      showAddDetail: false,
      dataInfo: {
        id: "",
        bpm: {},
        pmMaterialchecksList: [],   
      },
      isSubmitting: false,
      showButton: true,
      flag: hasPermission('material:check:pmMaterialcheck:edit'),
      x: 650, //x坐标
      y: 650, //y坐标
      addflag:hasPermission('btn:add:cailiaochoujian'),
      editflag:hasPermission('btn:edit:cailiaochoujian'),
    };
  },
  onLoad(e) {
    if (!!e.id) {
      this.showButton = true;
      this.getPmProjectSegmentationForm(e.id);
      this.dataInfo.id = e.id
    }
    if (!!e.xm) {
      this.showButton = true;
      this.dataInfo = JSON.parse(e.xm);
      //   巡检人
      this.dataInfo.state = 1;
    }

  },
  methods: {
    submit() {
      if (this.isSubmitting) {
        return;
      } else {
        this.isSubmitting = true;
        try {
            this.dataInfo.status = 4;
          this.$u.api.zfgs
            .pmProjectSegmentationSave(this.dataInfo)
            .then((res) => {
              if (res.result == "true") {
                this.$u.toast(res.message);
                setTimeout(() => {
                  uni.navigateBack({
                    delta: 1,
                  });
                }, 500);
              }else{
                this.$u.toast(res.message);
              }
            });
        } catch (error) {
          this.$u.toast(error.message);
        } finally {
          this.isSubmitting = false;
        }
      }
    },

    getPmProjectSegmentationForm(id) {
      this.$u.api.zfgs
        .pmProjectSegmentationForm({
          id: id,
        })
        .then((res) => {
          this.dataInfo = res.pmProjectSegmentation;
        });
    },

  },
};
</script>
<style lang="scss" scoped>
$all_width: 140rpx;
$all_height: 140rpx;
.movable-area {
  z-index: 999;
  height: 97vh;
  width: 650rpx;
  // max-width: 1152rpx;
  // 固定在右边
  top: -150rpx;
  position: fixed;
  right: $all_width;
  // 固定在右下角
  pointer-events: none; //此处要加，鼠标事件可以渗透
  .movable-view {
    width: $all_width;
    height: $all_height;
    pointer-events: auto; //恢复鼠标事件
    .cu-bar{
      width: 320rpx;
    }
  }
}
.action {
  color: #303133;
}
.cu-form-group {
  flex-wrap: wrap;
}
.text-sl {
  font-size: 22px !important;
}
.cu-bar1 {
  min-height: 80px;
}
.cu-btn {
  font-size: 16px;
  height: 40px;
}
.foot {
  z-index: 997;
  background: #fff;
}
.green {
  color: green;
}
.input-align {
  text-align: right;
}
.sub-title{
  flex-grow: 1; /* 让右侧内容占据剩余空间 */
  max-width: 200px; /* 或其他合适的最大宽度，超过这个宽度时内容会换行 */
  word-break: break-word; /* 或 overflow-wrap: break-word; 允许单词在必要时断开以适应宽度 */
}
.xm-title{
  flex-basis: 100px; /* 或其他合适的固定宽度，用于左侧标题 */
  flex-shrink: 0; /* 防止标题在小屏幕下收缩 */
  overflow: hidden; /* 可选，防止内容溢出 */
}
.text-xsl {
  font-size: 60rpx !important;
}
.flex-end {
  display: flex;
  justify-content: flex-end;
}
.text-xs {
  font-size: 18rpx !important;
}
.cu-item{
  border: 1px solid #39b54a;
}
.cuIcon-kb::before {
    // content 为空白
    display: inline-block;
    content: ' ';
    width: 18rpx;
    height: 100%;
    
}
</style>